Current Location: Home> Function Categories> dir

dir

Returns an instance of the Directory class
Name:dir
Category:Directory functions
Programming Language:php
One-line Description:Returns an instance of the Directory class.

Definition and usage

dir() function returns an instance of the Directory class. This function is used to read a directory, including the following:

  • The given directory to open
  • The handle and path properties of dir() are available
  • There are three methods for the handle and path attributes: read(), rewind() and close()

实例

使用 dir() 函数:

<?php
$d = dir(getcwd());

echo "Handle: " . $d->handle . "<br>";
echo "Path: " . $d->path . "<br>";

while (($file = $d->read()) !== false){
  echo "filename: " . $file . "<br>";
}
$d->close();
?>

结果:

Handle: Resource id #2
Path: /etc/php
filename: .
filename: ..
filename: ajax.gif
filename: books.xml
filename: cdcatalog.xml
filename: cd_catalog.xml
filename: index.asp
filename: demo_array.asp
filename: demo_array.htm
...
...
...

grammar

 dir ( directory , context ) ;
parameter describe
Directory Required. Specify the directory to be opened.
context Optional.
Similar Functions
Popular Articles